package com.example.projectmanagement.model.study;

import com.example.projectmanagement.model.User;
import jakarta.persistence.*;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import java.time.LocalDateTime;

@Entity
@Table(name = "user_lesson_progress", uniqueConstraints = {
    @UniqueConstraint(columnNames = {"user_id", "lesson_id"})
})
@Data
@NoArgsConstructor
@AllArgsConstructor
@EntityListeners(AuditingEntityListener.class)
public class UserLessonProgress {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id", nullable = false)
    private User user;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "lesson_id", nullable = false)
    private Lesson lesson;

    @Column(name = "status")
    private String status; // 未开始/学习中/已完成

    @Column(name = "viewed_duration")
    private Integer viewedDuration = 0; // 已观看时长（秒）

    @Column(name = "total_duration")
    private Integer totalDuration; // 总时长（秒）

    @CreatedDate
    @Column(name = "start_time")
    private LocalDateTime startTime;

    @LastModifiedDate
    @Column(name = "last_access_time")
    private LocalDateTime lastAccessTime;

    @Column(name = "completion_time")
    private LocalDateTime completionTime;
}